package com.module.rotary.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.dq.util.ToastUtil;
import com.module.rotary.R;
import com.module.rotary.entity.RotaryEntity;

public class CashRewardsAdapter extends BaseQuickAdapter<RotaryEntity, BaseViewHolder> {

    public CashRewardsAdapter() {
        super(R.layout.item_cash_rewards);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, RotaryEntity rotaryEntity) {

        baseViewHolder.setText(R.id.tvGodsName, rotaryEntity.getGoodsName())
                .setText(R.id.tvDebris1, rotaryEntity.getDebris1())
                .setText(R.id.tvDebris2, rotaryEntity.getDebris2())
                .setText(R.id.tvDebris3, rotaryEntity.getDebris3())
                .setText(R.id.tvDebris4, rotaryEntity.getDebris4())
                .setText(R.id.tvDebris5, rotaryEntity.getDebris5());

        final Context context = baseViewHolder.itemView.getContext();
        final int position = baseViewHolder.getLayoutPosition();
        TextView tvExchange = baseViewHolder.getView(R.id.tvExchange);
        View viewDebris1 = baseViewHolder.getView(R.id.viewDebris1);
        View viewDebris2 = baseViewHolder.getView(R.id.viewDebris2);
        View viewDebris3 = baseViewHolder.getView(R.id.viewDebris3);
        View viewDebris4 = baseViewHolder.getView(R.id.viewDebris4);
        View viewDebris5 = baseViewHolder.getView(R.id.viewDebris5);
        ImageView imgDebris1 = baseViewHolder.getView(R.id.imgDebris1);
        ImageView imgDebris2 = baseViewHolder.getView(R.id.imgDebris2);
        ImageView imgDebris3 = baseViewHolder.getView(R.id.imgDebris3);
        ImageView imgDebris4 = baseViewHolder.getView(R.id.imgDebris4);
        ImageView imgDebris5 = baseViewHolder.getView(R.id.imgDebris5);

        switch (position){
            case 0:
                imgDebris1.setImageResource(R.drawable.icon_sp_1_1);
                imgDebris2.setImageResource(R.drawable.icon_sp_1_2);
                imgDebris3.setImageResource(R.drawable.icon_sp_1_3);
                imgDebris4.setImageResource(R.drawable.icon_sp_1_4);
                imgDebris5.setImageResource(R.drawable.icon_sp_1_5);
                break;
            case 1:
                imgDebris1.setImageResource(R.drawable.icon_sp_2_1);
                imgDebris2.setImageResource(R.drawable.icon_sp_2_2);
                imgDebris3.setImageResource(R.drawable.icon_sp_2_3);
                imgDebris4.setImageResource(R.drawable.icon_sp_2_4);
                imgDebris5.setImageResource(R.drawable.icon_sp_2_5);
                break;
            case 2:
                imgDebris1.setImageResource(R.drawable.icon_sp_3_1);
                imgDebris2.setImageResource(R.drawable.icon_sp_3_2);
                imgDebris3.setImageResource(R.drawable.icon_sp_3_3);
                imgDebris4.setImageResource(R.drawable.icon_sp_3_4);
                imgDebris5.setImageResource(R.drawable.icon_sp_3_5);
                break;
            case 3:
                imgDebris1.setImageResource(R.drawable.icon_sp_4_1);
                imgDebris2.setImageResource(R.drawable.icon_sp_4_2);
                imgDebris3.setImageResource(R.drawable.icon_sp_4_3);
                imgDebris4.setImageResource(R.drawable.icon_sp_4_4);
                imgDebris5.setImageResource(R.drawable.icon_sp_4_5);
                break;
            case 4:
                imgDebris1.setImageResource(R.drawable.icon_sp_5_1);
                imgDebris2.setImageResource(R.drawable.icon_sp_5_2);
                imgDebris3.setImageResource(R.drawable.icon_sp_5_3);
                imgDebris4.setImageResource(R.drawable.icon_sp_5_4);
                imgDebris5.setImageResource(R.drawable.icon_sp_5_5);
                break;
        }

        if(rotaryEntity.isSmoke1){
            viewDebris1.setBackground(null);
        }
        if(rotaryEntity.isSmoke2){
            viewDebris2.setBackground(null);
        }
        if(rotaryEntity.isSmoke3){
            viewDebris3.setBackground(null);
        }
        if(rotaryEntity.isSmoke4){
            viewDebris4.setBackground(null);
        }
        if(rotaryEntity.isSmoke5){
            viewDebris5.setBackground(null);
        }

        tvExchange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.showShortToast(context, "集齐碎片后方可兑换");
            }
        });
    }
}
